<template>
  <div class="role-list">
    <ToolBar>
     
      <!-- <div style="float: right">
        <el-input
            placeholder="请输入角色名称！"
            size="small"
            style="width: 140px"
            v-model="params.name"
            @clear="searchRole"
            clearable>
        </el-input>
        <el-button @click="searchRole" type="success" icon="el-icon-search" size="small"></el-button>
      </div> -->
    </ToolBar>
    <el-table
        :data="roleData"
        border
        ref="table"
        style="width: 100%">
      <el-table-column
          prop="rId"
          label="角色key">
          <template slot-scope="scope">
                    <!-- <i class="el-icon-star-off"></i> -->
                    <span style="margin-left: 10px">
                      {{ scope.row.rId}}
                    </span>
          </template>
      </el-table-column>
      <el-table-column
          prop="rName"
          label="角色名称">
          <template slot-scope="scope">
                    <!-- <i class="el-icon-star-off"></i> -->
                    <span style="margin-left: 10px">
                      {{ scope.row.rName }}
                    </span>
                  </template>
      </el-table-column>
      <el-table-column
          label="是否有效"
          prop="isEffectice"
          :formatter="activeformat">
          
      </el-table-column>
      <el-table-column
          label="操作"
          :render-header="tableAction"
          width="120">
        <template slot-scope="scope">
         
          <el-button title="删除" @click="delrole(scope.row)" v-if="scope.row.isEffectice != '0'" type="danger" icon="el-icon-delete" size="small" circle></el-button>
          <el-button title="恢复" @click="delrole(scope.row)" v-else icon="el-icon-check" type="primary"  size="small" circle></el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- <RoleEdit
        :title="roleEditTitle"
        :dialogFormVisible="dialogFormVisible"
        :data="currentEditRole"
        @val-change="roleEditChange"
        @cancel="dialogFormVisible = false"
    >
    </RoleEdit> -->
    
  </div>
</template>

<script>
  // import ToolBar from '@/components/ToolBar.vue';
  // import HelpHint from '@/components/HelpHint.vue';
  import RoleEdit from './RoleEdit.vue'
  import { getRole as userApi} from "../../../api/user";
  import { findData } from "../../../api/user";
  import { delrole as delrole } from "../../../api/user";


  export default {
    data() {
      return {
        search:{
          isEffectice:"",
          name:""
        },
        // roleEditTitle: '角色编辑',
        // currentEditRole: false,
        // dialogFormVisible: false,
        // currentEditPermissions: false,
        roleData:{},
        params: {
          isEffectice:"",
          name: "",
        },

        
      }
    },
    created() {
      this.getRole();
    },
    methods: {
      getRole(){
         userApi()
        .then(r => {
          this.roleData = r;
          console.log(this.r);
        })
        .catch(_ => {
          console.log(_);
        });
      },
      getInfo(e) {
        console.log(e.currentTarget.innerText);
      },
      activeformat(row, column, cellValue, index){
            return cellValue==0?"失效":"有效";
      },
      
     
      editRole(data) {
        if (data) {
          this.currentEditRole = data;
        } else {
          this.currentEditRole = false;
        }

        this.dialogFormVisible = true;

      },
      UploadRole(data) {

      },
      
      delrole(row){
        let param = new URLSearchParams();
          param.append('rId',row.rId);
          param.append("rName", row.rName);
        if(row.isEffectice === 1){
           
          param.append("isEffectice",'0');
          
          delrole(param).then(r=>{
            console.log(param);
            setTimeout(() => {
              this.$notify({
                 title:"删除角色成功",
                 type:"success"
              });
            });
          }).catch(_=>{
              console.log("删除角色失败！");
          });
        }else{
            param.append("isEffectice",'1');
            delrole(param).then(r=>{
              console.log(param);
              setTimeout(() => {
                this.$notify({
                  title:"恢复角色成功",
                  type:"success"
                  
                });
              });
            }).catch(_=>{
                console.log("恢复角色失败！");
            });
          }
          let params = new URLSearchParams();
          let that = this;
          that.getRole(params);
      },
      deltext(isEffectice){
        return isEffectice==1?"恢复":"删除"
      }

    },
    components: {
     // ToolBar, HelpHint, RoleEdit
    }
  }
</script>
<style lang="scss">

</style>
